Skip to content

Conversation

Darren-Kelly-Unity
Copy link
Collaborator

@Darren-Kelly-Unity Darren-Kelly-Unity commented Sep 16, 2025

Description

You could cause multiple null or out of range exceptions if you press undo while editing a control scheme.
This is caused by undo causing the control scheme to be removed while you still have the edit window open.

Now the edit window will close immediately if you press undo while it's open.

Ticket:
https://jira.unity3d.com/browse/ISXB-1607

Video of fix (Usually undoing when editing the new control scheme would throw an exception / it could also cause other exceptions if the window was left open, therefore I now close it when this happens to avoid future issues):

Screen.Recording.2025-10-07.at.15.06.14.mov

Testing status & QA

Tested manually all the cases I could find until all exceptions were gone. There was multiple paths to create exceptions due to the asset being removed via undo.

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity: 2
  • Halo Effect: 1

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

…ed by Undoing the creation of it via ctrl+z.
@codecov-github-com
Copy link

codecov-github-com bot commented Sep 16, 2025

Codecov Report

Attention: Patch coverage is 14.28571% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...or/UITKAssetEditor/Views/InputActionsEditorView.cs 20.00% 12 Missing ⚠️
.../UITKAssetEditor/Commands/ControlSchemeCommands.cs 0.00% 6 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2237      +/-   ##
===========================================
- Coverage    68.14%   68.13%   -0.02%     
===========================================
  Files          367      367              
  Lines        53685    53700      +15     
===========================================
+ Hits         36585    36587       +2     
- Misses       17100    17113      +13     
Flag Coverage Δ
linux_2021.3_pkg 5.47% <ø> (ø)
linux_2021.3_project 70.40% <ø> (ø)
linux_2022.3_pkg 5.24% <0.00%> (-0.01%) ⬇️
linux_2022.3_project 65.23% <0.00%> (-0.02%) ⬇️
linux_6000.0_pkg 5.25% <0.00%> (-0.01%) ⬇️
linux_6000.0_project 68.04% <14.28%> (-0.02%) ⬇️
linux_6000.2_pkg 5.25% <0.00%> (-0.01%) ⬇️
linux_6000.2_project 68.03% <14.28%> (-0.02%) ⬇️
linux_trunk_pkg 5.25% <0.00%> (-0.01%) ⬇️
linux_trunk_project 68.03% <14.28%> (-0.02%) ⬇️
mac_2021.3_pkg 5.46% <ø> (ø)
mac_2021.3_project 70.41% <ø> (ø)
mac_2022.3_pkg 5.23% <0.00%> (-0.01%) ⬇️
mac_2022.3_project 65.25% <0.00%> (-0.02%) ⬇️
mac_6000.0_pkg 5.24% <0.00%> (-0.01%) ⬇️
mac_6000.0_project 68.06% <14.28%> (-0.02%) ⬇️
mac_6000.2_pkg 5.24% <0.00%> (-0.01%) ⬇️
mac_6000.2_project 68.06% <14.28%> (-0.02%) ⬇️
mac_trunk_pkg 5.24% <0.00%> (-0.01%) ⬇️
mac_trunk_project 68.06% <14.28%> (-0.02%) ⬇️
win_2021.3_pkg 5.47% <ø> (ø)
win_2021.3_project 70.49% <ø> (ø)
win_2022.3_pkg 5.24% <0.00%> (-0.01%) ⬇️
win_2022.3_project 65.33% <0.00%> (-0.03%) ⬇️
win_6000.0_pkg 5.25% <0.00%> (-0.01%) ⬇️
win_6000.0_project 68.13% <14.28%> (-0.02%) ⬇️
win_6000.2_pkg 5.25% <0.00%> (-0.01%) ⬇️
win_6000.2_project 68.13% <14.28%> (-0.02%) ⬇️
win_trunk_pkg 5.25% <0.00%> (-0.01%) ⬇️
win_trunk_project 68.13% <14.28%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...Editor/UITKAssetEditor/Views/ControlSchemesView.cs 0.00% <ø> (ø)
.../UITKAssetEditor/Commands/ControlSchemeCommands.cs 76.57% <0.00%> (-2.26%) ⬇️
...or/UITKAssetEditor/Views/InputActionsEditorView.cs 42.77% <20.00%> (-1.46%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Darren-Kelly-Unity Darren-Kelly-Unity changed the title FIX: out of range exception when pressing undo after creating and editing a new control scheme (ISXB-1607) (DRAFT) FIX: out of range exception when pressing undo after creating and editing a new control scheme (ISXB-1607) Sep 26, 2025
{
try
{
await Task.Delay(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This await Task.Delay(1) raises warning flags to me. What guarantees this is valid to execute 1 second from now?

  • Why does it have to be delayed?
  • It looks like this runs async but code being accessed do not seem to be thread safe?
  • Is there a logical condition not based on time when this is valid to execute?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it was something I added at the end to solve an exception but it's not the correct way to do this.

I have now resorted to just closing the window when an undo is triggered if it's open.

This has one side effect though that it will trigger the view to close in a case where it might not need to, definitely less bad than all the exceptions it could cause previously.

The best solution that I could not figure out a way to do would be to add the opening of the control scheme editor popup to the undo stack so that pressing undo would close it, I did find a way to possibly do this but it would add a good amount of complexity and would be quite hacky.

I chose not to go this route in the end as the undo api is not really designed to be used with things that are not Objects/GameObjects.


s_OnPasteCutElements.Add(this);

Undo.undoRedoPerformed += CheckForInvalidControlSchemeInOneFrame;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am misunderstanding this PR/issue so I want to check whether this problem is if you undo text editing while in text editing mode? Such editing should not have been applied yet to any serializedProperty right or am I misunderstanding this issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit different than that, basically the last undo when opening a control scheme to edit is the creation of the asset.

Therefore undoing while editing the name actually deletes the asset.
This of course causes exceptions when inside the edit window if you try to alter the asset or even try to close it.

My solution I have landed on for now is to close the control scheme view when this happens and revert to selecting the all controls control scheme now instead.

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly asking question at this point since I am not sure I understand this fix or problem yet....

@Darren-Kelly-Unity Darren-Kelly-Unity marked this pull request as draft October 7, 2025 10:18
@Darren-Kelly-Unity Darren-Kelly-Unity marked this pull request as ready for review October 7, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants